'use strict';

module.exports = appInfo => {
  const config = exports = {};

  // 基础配置
  config.base = {
    name: '',
    chineseName: 'GlobeCat多商户购物系统',
    domain: 'localhost',
  };

  config.bodyParser = {
    enableTypes: [ 'json', 'form', 'text' ],
    extendTypes: {
      text: [ 'text/xml', 'application/xml' ],
    },
    jsonLimit: '2mb',
  };

  config.custom = {
    origin: `https://api.${config.base.domain}/`,
    redis: {
      host: '127.0.0.1',
      port: '6379',
      password: '',
    },
  };

  config.jwt = {
    secret: '',
  };
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1546571409448_7014';

  config.cors = {
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
    credentials: true,
  };

  config.redis = {
    client: {
      host: config.custom.redis.host,
      port: config.custom.redis.port,
      password: config.custom.redis.password,
      db: '0',
    },
  };

  config.security = {
    csrf: {
      enable: false,
    },
    domainWhiteList: [ `https://console.${config.base.domain}`, 'http://localhost:8000' ],
  };

  exports.static = {
    prefix: '/',
  };
  // add your config here
  config.middleware = [];
  // 第三方配置
  config.thirdParty = {
  // 阿里云短信
    aliyunSms: {
      accessKeyId: '',
      secretAccessKey: '',
      SignName: '',
      TemplateCode: '',
    },
    // 七牛云
    qiniu: {
      accessKey: '',
      secretKey: '',
      bucket: '',
      domains: {
        image: '',
      },
    },
    // 微信小程序
    wechatWeapp: {
      appId: '',
      appSecret: '',
    },
    // 微信支付
    wechatPay: {
      merchantId: '',
      secret: '',
    },
  };
  // {app_root}/config/plugin.js
  exports.view = {
    defaultViewEngine: 'nunjucks',
    mapping: {
      '.njk': 'nunjucks',
    },
  };
  config.weappSDK = {
    appId: config.thirdParty.wechatWeapp.appId,
    appSecret: config.thirdParty.wechatWeapp.appSecret,
  };
  config.wechatPay = {
    client: {
      bodyPrefix: config.base.chineseName,
      appId: config.thirdParty.wechatWeapp.appId,
      merchantId: config.thirdParty.wechatPay.merchantId,
      secret: config.thirdParty.wechatPay.secret,
      notifyUrl: `${config.custom.origin}notify/wechat_pay`,
    },
  };

  return config;
};
